class Book(val b_name: String, val b_author: String, val b_isbn: String) {
    def borrowBook(library: Library): Unit = {
        // 检查书籍是否在可用书籍列表中
        if (library.us_book.contains(b_name)) {
            println(s"借了${b_name}")
            library.borrow_book(this)
        } else {
            println(s"书籍${b_name} 不可借阅，因为它不在可用书籍列表中。")
        }
    }
    def returnBook(library: Library): Unit = {
        println(s"一个月之后还了${b_name}")
        library.return_book(this)
    }
}

class Library(var us_book: List[String], var bow_book: List[String]) {
    def add_book(new_books: List[String]): Unit = {
        us_book = us_book ++ new_books
        println(s"新加了书: ${new_books.mkString(", ")}")
        println(s"加了书之后的书的列表为: ${us_book.mkString(", ")}")
    }
    def borrow_book(book: Book): Unit = {
        bow_book = bow_book :+ book.b_name
        us_book = us_book.filterNot(_ == book.b_name)
        println(s"借了书之后的已借出书的列表为${bow_book.mkString(",")}")
        println(s"借了书之后的可用书籍列表为${us_book.mkString(", ")}")
    }
    def return_book(book: Book): Unit = {
        println(s"还了书: ${book.b_name}")
        bow_book = bow_book.filterNot(_ == book.b_name)
        us_book = us_book :+ book.b_name
        println(s"还了书之后的已借出书的列表为${bow_book.mkString(",")}")
        println(s"还了书之后的可用书籍列表为${us_book.mkString(", ")}")
    }
}
object Book {
    def apply(b_name: String, b_author: String, b_isbn: String): Book = {
        new Book(b_name, b_author, b_isbn)
    }
    def unapply(book: Book): Option[(String, String, String)] = {
        Some(book.b_name, book.b_author, book.b_isbn)
    }
}
object Library {
    def apply(us_book: List[String], bow_book: List[String]): Library = {
        new Library(us_book, bow_book)
    }
    def unapply(library: Library): Option[(List[String], List[String])] = {
        Some(library.us_book, library.bow_book)
    }
}
object Main {
    def main(args: Array[String]): Unit = {
        val book = Book("呐喊", "author1", "isbn1")
        
        val library = Library(List("呐喊", "活着", "平凡的世界"), List("百年孤独", "稻草人", "简爱"))
        
        library.add_book(List("追风筝的人", "草房子"))
        book.borrowBook(library)
        println("------------------------------")
        book.returnBook(library)
    }
}